package com.alibaba.cirtus.ots.application.app.ability.facade.v2serviceimpl;

import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSONObject;
import com.epoch.app.crunifiedinventory.service.CrUnifiedInventoryService;
import com.epoch.app.otsapplicationappsdk.transportgoodsdetail.dto.RenderRequest;
import com.epoch.app.otsapplicationappsdk.transportgoodsdetail.service.TransportGoodsDetailService;
import com.epoch.app.crunifiedinventory.model.dto.MnTmsShipDetailListTestRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TransportGoodsDetailV2ServiceImpl implements TransportGoodsDetailService {

    private static Log log = Log.getLogger(TransportGoodsDetailV2ServiceImpl.class);
//    @Resource
//    private OtsUnifiedInventoryService otsUnifiedInventoryService;
    @Resource
    private CrUnifiedInventoryService otsUnifiedInventoryService;
    @Override
    public Object render(RenderRequest renderRequest) {
        log.info("装运单明细渲染 请求参数 {} " , JSONObject.toJSONString(renderRequest));
        JSONObject result = new JSONObject();
        JSONObject request = JSONObject.parseObject( JSONObject.toJSONString(renderRequest.getRequestBody()));
        if (null==request|| StringUtils.isBlank(request.getString("shipOrderId"))){
            result.put("success",false);
            result.put("message","外部单号不能为空!");
            return result;
        }

        try {
            MnTmsShipDetailListTestRequest mnTmsShipDetailListTestRequest = new MnTmsShipDetailListTestRequest();
            mnTmsShipDetailListTestRequest.setShipOrderId(request.getString("shipOrderId"));
            return otsUnifiedInventoryService.mnTmsShipDetailListTest(mnTmsShipDetailListTestRequest);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("装运单明细异常");
        }
        return result;
    }

}
